package com.wangsh.usersCenter.web.back.controller;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wangsh.usersCenter.common.controller.BaseController;
import com.wangsh.usersCenter.common.pojo.ApiResponse;
import com.wangsh.usersCenter.common.pojo.ApiResponseEnum;
import com.wangsh.usersCenter.common.util.ConstatFinalUtil;
import com.wangsh.usersCenter.common.util.PageInfoUtil;
import com.wangsh.usersCenter.system.pojo.ACate;
import com.wangsh.usersCenter.system.pojo.ACateEnum;
import com.wangsh.usersCenter.system.pojo.ARegion;
import com.wangsh.usersCenter.system.pojo.ASysIp;
import com.wangsh.usersCenter.system.pojo.ASysLog;
import com.wangsh.usersCenter.system.pojo.ASysPro;
import com.wangsh.usersCenter.system.service.ISystemDbService;
import com.wangsh.usersCenter.system.service.ISystemOperService;
import com.wangsh.usersCenter.users.pojo.AAdmins;
import com.wangsh.usersCenter.users.service.IUsersDbService;

/**
 * 全局分类和全局地区的controller
 * 
 * @author wangsh
 */
@Controller
@RequestMapping("/back/system/")
public class SystemBackController extends BaseController
{
	@Resource
	private ISystemDbService systemDbService;
	@Resource
	private IUsersDbService usersDbService;
	@Resource
	private ISystemOperService systemOperService;

	/**
	 * 全国地区 列表页面
	 * 
	 * @return
	 */
	@RequestMapping("/regionList")
	public String regionList(HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--regionList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/*
		 * 查询数据库 所有的数据以JSON的形式返回
		 */
		ApiResponse<ARegion> response = this.systemDbService.findCondListRegionService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/system/regionList";
	}

	/**
	 * 打开添加全国地区页面
	 * 
	 * @return
	 */
	@RequestMapping("/regionInsert")
	public String regionInsert()
	{
		ConstatFinalUtil.SYS_LOGGER.info("--regionInsert--");
		return "/back/system/regionInsert";
	}

	/**
	 * 添加全国地区提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/regionInsertSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String regionInsertSubmit(String pubTimeStr, ARegion Region)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--regionInsertSubmit--");
		/* 为对象赋值 */
		Region.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		Region.setCreateTime(new Date());
		Region.setUpdateTime(new Date());
		/* 保存结果 */
		ApiResponse response = this.systemDbService.saveOneRegionService(Region);
		ConstatFinalUtil.SYS_LOGGER.info("--全国地区添加返回结果:{}--", response.toJSON());
		Map<String,Object> condMap = new HashMap<String, Object>();
		condMap.put("status",1);
		ApiResponse<AAdmins> findCondListAdminsService = this.usersDbService.findCondListAdminsService(null, condMap);
		List<AAdmins> dataListJava = findCondListAdminsService.getDataListJava();
		for (AAdmins aAdmins : dataListJava)
		{
			this.redisUtil.delete(aAdmins.getRoleId()+"");
		}
		return response.toJSON().toJSONString();
	}

	/**
	 * 打开更新全国地区页面
	 * 
	 * @return
	 */
	@RequestMapping("/regionUpdate")
	public String regionUpdate(String id, String operType, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--regionUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ARegion> response = this.systemDbService.findOneRegionService(condMap);
		/* 存储request */
		model.addAttribute("response", response.toJSON());
		if ("update".equalsIgnoreCase(operType))
		{
			return "/back/system/regionUpdate";
		}
		return "/back/system/regionInfo";
	}

	/**
	 * 更新全国地区提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/regionUpdateSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String regionUpdateSubmit(String id, HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--regionUpdateSubmit--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ARegion> response = this.systemDbService.findOneRegionService(condMap);
		/* 获取java对象 */
		ARegion Region = response.getDataOneJava();
		/* 接收参数 */
		String name = request.getParameter("name");
		String status = request.getParameter("status");
		String pubTimeStr = request.getParameter("pubTimeStr");
		String content = request.getParameter("content");
		String parentId = request.getParameter("parentId");
		String pinyin = request.getParameter("pinyin");
		String areacode = request.getParameter("areacode");
		String leafStatus = request.getParameter("leafStatus");
		/* 设置属性 */
		Region.setName(name);
		Region.setContent(content);
		Region.setStatus(Byte.valueOf(status));
		Region.setParentId(Integer.valueOf(parentId));
		Region.setPinyin(pinyin);
		Region.setAreacode(areacode);
		Region.setLeafStatus(Byte.valueOf(leafStatus));
		Region.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		Region.setUpdateTime(new Date());
		/* 数据库操作 */
		ApiResponse dbRes = systemDbService.updateOneRegionService(Region);
		condMap.clear();
		condMap.put("status",1);
		ApiResponse<AAdmins> findCondListAdminsService = this.usersDbService.findCondListAdminsService(null, condMap);
		List<AAdmins> dataListJava = findCondListAdminsService.getDataListJava();
		/*清除redis缓存*/
		for (AAdmins aAdmins : dataListJava)
		{
			this.redisUtil.delete(aAdmins.getRoleId()+"");
		}
		ConstatFinalUtil.SYS_LOGGER.info("--全国地区添加返回结果:{}--", dbRes.toJSON());
		return dbRes.toJSON().toJSONString();
	}
	/* ===全国地区结束=== */
	/* ===日志开始=== */
	/**
	 * 日志列表页面
	 * 
	 * @return
	 */
	@RequestMapping("/logList")
	public String logList(HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--logList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/* 额外的搜索条件 */
		String relaId = request.getParameter("relaId");
		if(relaId == null)
		{
			relaId = "" ;
		}
		request.setAttribute("relaId", relaId);
		condMap.put("relaId", relaId);
		
		String sysIpId = request.getParameter("sysIpId");
		if(sysIpId == null)
		{
			sysIpId = "" ;
		}
		request.setAttribute("sysIpId", sysIpId);
		condMap.put("sysIpId", sysIpId);
		
		/* 查询日志类型 */
		String logType = request.getParameter("logType");
		if(logType == null)
		{
			logType = "" ;
		}
		request.setAttribute("logType", logType);
		condMap.put("logType", logType);
		
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<ASysLog> apiResponse = this.systemDbService.findCondListLogService(pageInfoUtil, condMap);
		model.addAttribute("response", apiResponse.toJSON());
		return "/back/system/logList";
	}

	/**
	 * 打开添加日志页面
	 * 
	 * @return
	 */
	@RequestMapping("/logInsert")
	public String logInsert(HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--logInsert--");
		return "/back/system/logInsert";
	}

	/**
	 * 添加日志提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/logInsertSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String logInsertSubmit(String pubTimeStr, ASysLog log)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--logInsertSubmit--");
		/* 为对象赋值 */
		log.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		log.setCreateTime(new Date());
		log.setUpdateTime(new Date());
		/* 保存结果 */
		ApiResponse response = this.systemDbService.saveOneLogService(log);
		ConstatFinalUtil.SYS_LOGGER.info("--日志添加返回结果:{}--", response.toJSON());
		return response.toJSON().toJSONString();
	}

	/**
	 * 打开更新日志页面
	 * 
	 * @return
	 */
	@RequestMapping("/logUpdate")
	public String logUpdate(String id, String operType, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--logUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysLog> response = this.systemDbService.findOneLogService(condMap);
		model.addAttribute("response", response.toJSON());
		if ("update".equalsIgnoreCase(operType))
		{
			return "/back/system/logUpdate";
		}
		return "/back/system/logInfo";
	}

	/**
	 * 更新日志提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/logUpdateSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String logUpdateSubmit(String id, HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--logUpdateSubmit--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysLog> response = this.systemDbService.findOneLogService(condMap);
		/* 获取java对象 */
		ASysLog log = response.getDataOneJava();
		/* 接收参数 */
		String name = request.getParameter("name");
		String content = request.getParameter("content");
		String status = request.getParameter("status");
		String ip = request.getParameter("ip");
		String pubTimeStr = request.getParameter("pubTimeStr");
		/* 设置属性 */
		log.setName(name);
		log.setIp(ip);
		//log.setAdminsId(Integer.valueOf(adminsId));
		log.setContent(content);
		log.setStatus(Byte.valueOf(status));
		log.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		log.setUpdateTime(new Date());
		/* 数据库操作 */
		ApiResponse dbRes = systemDbService.updateOneLogService(log);
		ConstatFinalUtil.SYS_LOGGER.info("--日志添加返回结果:{}--", dbRes.toJSON());
		return dbRes.toJSON().toJSONString();
	}
	/* ===日志结束=== */
	/* ===全局分类开始=== */

	/**
	 * 全局分类列表页面
	 * 
	 * @return
	 */
	@RequestMapping("/cateList")
	public String cateList(HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		condMap.put("extend", "true");
		/*
		 * 查询数据库 所有的数据以JSON的形式返回
		 */
		ApiResponse<ACate> response = this.systemDbService.findCondListCateService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/system/cateList";
	}

	/**
	 * 打开添加全局分类页面
	 * 
	 * @return
	 */
	@RequestMapping("/cateInsert")
	public String cateInsert()
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateInsert--");
		return "/back/system/cateInsert";
	}

	/**
	 * 添加全局分类提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/cateInsertSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String cateInsertSubmit(String pubTimeStr, ACate Cate, HttpServletRequest request)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateInsertSubmit--");
		/* 为对象赋值 */
		Cate.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		AAdmins admins = (AAdmins) request.getSession().getAttribute("admins");
		Cate.setCreateId(admins.getId());
		Cate.setUpdateId(admins.getId());
		Cate.setCreateTime(new Date());
		Cate.setUpdateTime(new Date());
		/* 保存结果 */
		ApiResponse response = this.systemDbService.saveOneCateService(Cate);
		ConstatFinalUtil.SYS_LOGGER.info("--全局分类添加返回结果:{}--", response.toJSON());
		return response.toJSON().toJSONString();
	}

	/**
	 * 打开更新全局分类页面
	 * 
	 * @return
	 */
	@RequestMapping("/cateUpdate")
	public String cateUpdate(String id, String operType, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ACate> response = this.systemDbService.findOneCateService(condMap);
		/* 存储request */
		model.addAttribute("response", response.toJSON());
		if ("update".equalsIgnoreCase(operType))
		{
			return "/back/system/cateUpdate";
		}
		return "/back/system/cateInfo";
	}

	/**
	 * 更新全局分类提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/cateUpdateSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String cateUpdateSubmit(String id, HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateUpdateSubmit--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ACate> response = this.systemDbService.findOneCateService(condMap);
		/* 获取java对象 */
		ACate Cate = response.getDataOneJava();
		int parentIdBefore = Cate.getParentId();
		/* 接收参数 */
		String updateId = request.getParameter("updateId");
		String name = request.getParameter("name");
		String status = request.getParameter("status");
		String pubTimeStr = request.getParameter("pubTimeStr");
		String content = request.getParameter("content");
		String parentIdAfter = request.getParameter("parentId");
		/* 设置属性 */
		Cate.setUpdateId(Integer.valueOf(updateId));
		Cate.setName(name);
		Cate.setContent(content);
		Cate.setStatus(Byte.valueOf(status));
		Cate.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		Cate.setParentId(Integer.valueOf(parentIdAfter));
		Cate.setUpdateTime(new Date());
		/* 数据库操作 */
		ApiResponse dbRes = systemDbService.updateOneCateService(Cate);
		if (parentIdBefore!=Integer.valueOf(parentIdAfter))
		{
			condMap.clear();
			condMap.put("parentId", parentIdBefore);
			ApiResponse<ACate> findCondListCateService = this.systemDbService.findCondListCateService(null,condMap);
			if (findCondListCateService.getCode()==-1||findCondListCateService.getDataListJava()==null)
			{
				condMap.put("id",parentIdBefore);
				ApiResponse<ACate> findOneCateService = this.systemDbService.findOneCateService(condMap);
				ACate dataOneJava2 = findOneCateService.getDataOneJava();
				dataOneJava2.setLeafStatus(Byte.valueOf("1"));
				ApiResponse<Object> updateOneCateService = systemDbService.updateOneCateService(dataOneJava2);
			}
		}
		ConstatFinalUtil.SYS_LOGGER.info("--全局分类添加返回结果:{}--", dbRes.toJSON());
		return dbRes.toJSON().toJSONString();
	}

	/**
	 * 全局分类树形结构
	 * 
	 * @return
	 */
	@RequestMapping("/cateTree")
	public String roleMenuTreeInsert(HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--cateTree--");
		/* 查询所有启用的全局分类 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("status", ACateEnum.STATUS_ENABLE.getStatus());
		ApiResponse<ACate> response = this.systemDbService.findCondListCateService(null, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/system/cateTree";
	}

	/* ===全局分类结束=== */
	/* ===系统配置开始=== */
	/**
	 * 系统配置列表页面
	 * 
	 * @return
	 */
	@RequestMapping("/sysProList")
	public String sysProList(HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/*
		 * 查询数据库 所有的数据以JSON的形式返回
		 */
		ApiResponse<ASysPro> response = this.systemDbService.findCondListSysProService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/system/sysProList";
	}

	/**
	 * 打开添加系统配置页面
	 * 
	 * @return
	 */
	@RequestMapping("/sysProInsert")
	public String sysProInsert(HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProInsert--");
		return "/back/system/sysProInsert";
	}

	/**
	 * 添加系统配置提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/sysProInsertSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String sysProInsertSubmit(String pubTimeStr, ASysPro sysPro)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProInsertSubmit--");
		/* 为对象赋值 */
		sysPro.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		sysPro.setCreateTime(new Date());
		sysPro.setUpdateTime(new Date());
		/* 保存结果 */
		ApiResponse response = this.systemDbService.saveOneSysProService(sysPro);
		ConstatFinalUtil.SYS_LOGGER.info("--系统配置添加返回结果:{}--", response.toJSON());
		return response.toJSON().toJSONString();
	}

	/**
	 * 打开更新系统配置页面
	 * 
	 * @return
	 */
	@RequestMapping("/sysProUpdate")
	public String sysProUpdate(String id, String operType, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysPro> response = this.systemDbService.findOneSysProService(condMap);
		/* 存储request */
		model.addAttribute("response", response.toJSON());
		if ("update".equalsIgnoreCase(operType))
		{
			return "/back/system/sysProUpdate";
		}
		return "/back/system/sysProInfo";
	}

	/**
	 * 更新系统配置提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/sysProUpdateSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String sysProUpdateSubmit(String id, HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProUpdateSubmit--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysPro> response = this.systemDbService.findOneSysProService(condMap);
		/* 获取java对象 */
		ASysPro sysPro = response.getDataOneJava();
		/* 接收参数 */
		String name = request.getParameter("name");
		String engName = request.getParameter("engName");
		String vals = request.getParameter("vals");
		String updateTime = request.getParameter("updateTimeStr");
		String content = request.getParameter("content");
		String proType = request.getParameter("proType");
		String status = request.getParameter("status");
		/* 设置属性 */
		sysPro.setName(name);
		sysPro.setEngName(engName);
		sysPro.setVals(vals);
		sysPro.setContent(content);
		sysPro.setStatus(Byte.valueOf(status));
		sysPro.setProType(Byte.valueOf(proType));
		sysPro.setUpdateTime(new Date());
		/* 数据库操作 */
		ApiResponse dbRes = systemDbService.updateOneSysProService(sysPro);
		ConstatFinalUtil.SYS_LOGGER.info("--系统配置更新返回结果:{}--", dbRes.toJSON());
		return dbRes.toJSON().toJSONString();
	}
	/* ===系统配置结束=== */
	/* ===ip列表置结束=== */
	/**
	 * ip列表页面
	 * @return
	 */
	@RequestMapping("/ipList")
	public String ipList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--ipList--");
		String id =request.getParameter("id");
		request.setAttribute("id",id);
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		condMap.put("id",id);
		ApiResponse<ASysIp> response = this.systemDbService.findCondListSysIpService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/system/ipList";
	}

	/**
	 * 打开添加ip页面
	 * @return
	 */
	@RequestMapping("/ipInsert")
	public String ipInsert()
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysIpInsert--");
		return "/back/system/ipInsert";
	}
	
	/**
	 * 添加ip提交操作
	 * @return
	 */
	@RequestMapping(value = "/ipInsertSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String ipInsertSubmit(String ip , ASysIp sysip , HttpServletRequest request)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--ipInsertSubmit--");
		sysip.setName(sysip.getName());
		/* 返回Ip */
		ApiResponse<ASysIp> apiResponse = this.systemOperService.operFindIp(ip);
		return apiResponse.toJSON().toJSONString();
	}
	
	/**
	 * 打开更新ip页面
	 * @return
	 */
	@RequestMapping("/ipUpdate")
	public String ipUpdate(String id , String operType , Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--ipUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysIp> response = this.systemDbService.findOneSysIpService(condMap);
		/* 存储request */
		model.addAttribute("response", response.toJSON());
		
		if("update".equalsIgnoreCase(operType))
		{
			return "/back/system/ipUpdate";
		}
		return "/back/system/ipInfo";
	}
	
	/**
	 * 添加ip提交操作
	 * @return
	 */
	@RequestMapping(value = "/ipUpdateSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String ipUpdateSubmit(String id,
			HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--ipUpdateSubmit--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysIp> response = this.systemDbService.findOneSysIpService(condMap);
		/* 获取java对象 */
		ASysIp sysIp = response.getDataOneJava() ;
		
		/* 接收参数 */
		String name = request.getParameter("name");
		String ip = request.getParameter("ip");
		String ipStr = request.getParameter("ipStr");
		String isp = request.getParameter("isp");
		String aresponse = request.getParameter("response");
		String content = request.getParameter("content");
		String status = request.getParameter("status");
		String pubTimeStr = request.getParameter("pubTimeStr");
		/* 设置属性 */
		sysIp.setName(name);
		sysIp.setIp(ip);
		sysIp.setIpStr(ipStr);
		sysIp.setIsp(isp);
		sysIp.setResponse(aresponse);
		sysIp.setContent(content);
		sysIp.setStatus(Byte.valueOf(status));		
		sysIp.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		sysIp.setUpdateTime(new Date());
		/* 数据库操作 */
		ApiResponse dbRes = systemDbService.updateOneSysIpService(sysIp);
		ConstatFinalUtil.SYS_LOGGER.info("--ip添加返回结果:{}--",dbRes.toJSON());
		return dbRes.toJSON().toJSONString();
	}
	
	/**
	 * ip批量操作
	 * @return
	 */
	@RequestMapping(value = "/ipBatch" , produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String ipBatch(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysIpBatch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");
		
		/* 操作类型 */
		String operType = request.getParameter("operType");
		ConstatFinalUtil.SYS_LOGGER.info("--------{}--",operType);
		if(ids != null)
		{
			//ConstatFinalUtil.SYS_LOGGER.info("status的值不不不不不为null");
			int totalNum = ids.length ; 
			int succedNum = 0 ; 
			int failedNum = 0 ; 
			for (int i = 0; i < ids.length; i++)
			{
				String id = ids[i];
				if("status".equalsIgnoreCase(operType))
				{
					String status = request.getParameter("status");
					ConstatFinalUtil.SYS_LOGGER.info("--------{}--",status);
					condMap.clear();
					condMap.put("id", id);
					ApiResponse<ASysIp> apiResponseDb = this.systemDbService.findOneSysIpService(condMap);
					ASysIp sysIp = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					sysIp.setStatus(Byte.valueOf(status));
					sysIp.setPubTime(new Date());
					
					ApiResponse<Object> ipClassResponse = this.systemDbService.updateOneSysIpService(sysIp);
					if(ipClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum ++ ; 
					}else
					{
						failedNum ++ ; 
					}
				}
			}			
			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		//ConstatFinalUtil.SYS_LOGGER.info("status的值为null");
		return apiResponse.toJSON().toJSONString();
	}
	/* ========ip-代理列表=====*/
}
